stage.set_background("halfcourt")
sprite = codesters.Sprite("player4")
sprite.go_to(215, -175)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
ball = codesters.Sprite("basketball")
x = random.randint(-100, 150)
ball.go_to(x, -25)
stage.set_gravity(10)
stage.set_bounce(.8)
ball.set_gravity_off()
net.set_gravity_off()
left_count = 0
down_count = 0
def left_key():
ball.move_left(10)
global left_count
left_count += 1
# add other actions...
stage.event_key("left", left_key)
def down_key():
ball.move_down(10)
global down_count
down_count += 1
# add other actions...
stage.event_key("down", down_key)
def space_bar():
ball.set_gravity_on()
ball.set_x_speed(left_count)
ball.set_y_speed(down_count)
# add other actions...
stage.event_key("space", space_bar)
t = codesters.Teacher()
event = t.find_text('collision')
handler = t.find_text('event_collision')
col_type = t.find_function('get_image_name')
try:
tval1 = event[0][1]
except:
tval1 = "DNE"
try:
tval2 = handler[0][1]
except:
tval2 = "DNE"
try:
tval3 = col_type[0][1]
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1.replace(' ', '') == 'defcollision(ball,hit_sprite):', "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Collision with Other Sprite event to your program?")
t1.add_failure('ball' not in tval1, "Did you replace the word sprite in the first line with ball?")
t1.add_failure('hit_ball' in tval1, "Oops! Make sure only change the first word sprite to ball.")
t1.add_failure(tval1.replace(' ', '') != 'defcollision(ball,hit_sprite):', "Make sure to change the sprite in the first line to ball!")
t2 = TestObjective()
t2.add_success(tval2.replace('', '')=='ball.event_collision(collision)', "Great job!")
t2.add_failure(tval2 == "DNE", "Oops! Did you delete the last line of your collision event?")
t2.add_failure('sprite,' in tval2, "Make sure you change the word sprite to ball in the last line of your Collision Event!")
t2.add_failure(tval2.replace('', '')!='ball.event_collision(collision)', "Make sure you change sprite to ball in the last line of the Collision Event.")
t3 = TestObjective()
t3.add_success('hit_sprite' in tval3, "Great job!")
t3.add_failure(tval3 == "DNE", "Oops! Make sure you use Collision with Other Sprite.")
t3.add_failure('hit_ball' in tval3, "Oops! Make sure you're only changing the first line of the Collision Event.")
t3.add_failure('hit_sprite' not in tval3, "Oops! Try using a Collision with Other Sprite event!")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)